// app.js
App({
  onLaunch() {
         // 隐藏系统tabbar
         wx.hideTabBar();

         // 获取设备信息
         this.getSystemInfo();
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      }
    })
  },
  onShow: function () {
    //隐藏系统tabbar
    wx.hideTabBar();
  },

  getSystemInfo: function () {
    let t = this;
    wx.getSystemInfo({
      success: function (res) {
        t.globalData.systemInfo = res;
      }
    });
  },

  editTabbar: function () {
    let tabbar = this.globalData.tabBar;
    let currentPages = getCurrentPages();
    let _this = currentPages[currentPages.length - 1];
    let pagePath = _this.route;
    (pagePath.indexOf('/') != 0) && (pagePath = '/' + pagePath);
    for (let i in tabbar.list) {
      tabbar.list[i].selected = false;
      (tabbar.list[i].pagePath == pagePath) && (tabbar.list[i].selected = true);
    }
    _this.setData({
      tabbar: tabbar
    });
  },
  globalData: {
    userInfo: null,
    
    tabBar:{
      "backgroundColor": "#ffffff",
      "color": "#CCCCCC",
      "selectedColor": "#88bf01",
    "list": [
      {
        "pagePath": "/pages/index/index",
        "text": "首页",
        "iconPath": "/images/tabBar/笔记，记录.png",
        "selectedIconPath": "/images/tabBar/笔记，记录 (1).png"
      },
      {
        "pagePath": "/pages/logs/logs",
        "text": "助手",
        "iconPath": "/images/tabBar/语音-1.png",
        "selectedIconPath": "/images/tabBar/语音-1 (1).png"
      },
      {
        "pagePath": "/pages/middle/middle",
        "iconPath": "/images/tabBar/plus-circle-fill.png",
        "isSpecial": true,
        "text": "常用"
      },
      {
        "pagePath": "/pages/analyze/analyze",
        "text": "分析",
        "iconPath": "/images/tabBar/分析.png",
        "selectedIconPath": "/images/tabBar/分析 (1).png"
      },
      {
        "pagePath": "/pages/my/my",
        "text": "我的",
        "iconPath": "/images/tabBar/我的.png",
        "selectedIconPath": "/images/tabBar/我的 (1).png"
      }
    ]
  }
  },
  //设置tabbar的选中 添加一个全局方法
// getTabBar方法为自定义组件下的方法
 getCurrentTabbar(selected, that) {
  if (typeof that.getTabBar === 'function' &&
      that.getTabBar()) {
      that.getTabBar().setData({
          selected: selected
      })
  }
}
})
